#include <iostream>
using namespace std;
#define LEN 100005

struct Task {
public:
    char name[100];
    int t;
};

Task qu[LEN];
int head, tail, n;

void enqueue(const Task &x) {
    qu[tail] = x;
    tail = (tail + 1) % LEN;
}
Task dequeue() {
    Task x = qu[head];
    head = (head + 1) % LEN;
    return std::move(x);
}
// 返回最小值
inline int min (const int &a, const int & b) { return a < b ? a : b;}

int main() {
    int elaps = 0, c;
    int i, q;
    Task u;
    cin >> n >> q;
    for (int i = 1; i <= n; ++i) {
        cin >> qu[i].name >> qu[i].t;
    }
    head = 1; tail = n + 1;
    while (head != tail) {
        u = dequeue();
        c = min(q, u.t);
        u.t -= c;
        elaps += c;
        if (u.t > 0) enqueue(u);
        else {
            cout << u.name << " " << elaps << endl;
        }
    }
}
